<template>
  <div class="class-table">
    <!-- 搜索 -->
    <div style="text-align:center;margin-top:10px;">
      <span>学期：</span>
      <el-select v-model="search_term" filterable placeholder="请输入学期" style="width:120px">
        <el-option
          v-for="(item,index) in term_list"
          :key="'g'+index"
          :label="item.term_name"
          :value="item.term_id"
        >{{item.term_name}}</el-option>
      </el-select>
      <span>周次：</span>
      <el-select v-model="search_week" filterable placeholder="请输入周次" style="width:120px">
        <el-option
          v-for="(item,index) in week_list"
          :key="'g'+index"
          :label="item.week_name"
          :value="item.week_id"
        >{{item.week_name}}</el-option>
      </el-select>
      <el-button type="primary" icon="el-icon-search" @click="search_lessonSchedule">搜索</el-button>
    </div>
    <div class="table-wrapper">
      <div class="tabel-container">
        <table>
          <thead>
            <tr>
              <th>时间</th>
              <th
                v-for="(weekNum, weekIndex) in classTableData.courses.length"
                :key="weekIndex"
              >{{'周' + digital2Chinese(weekIndex, 'week')}}</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(lesson, lessonIndex) in classTableData.lessons" :key="lessonIndex">
              <th>
                <p>{{'第' + digital2Chinese(lessonIndex+1) + "节"}}</p>
                <p class="period">{{ lesson }}</p>
              </th>

              <td
                v-for="(course, courseIndex) in classTableData.courses"
                :key="courseIndex"
              >{{classTableData.courses[courseIndex][lessonIndex] || '-'}}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      search_term: "", //学期---输入的搜索条件
      search_week: "", //周次---输入的搜索条件
      term_list: [], //学期列表
      week_list: [], //周次列表
      classTableData: {
        lessons: [
          "08:00-09:00",
          "09:00-10:00",
          "10:00-11:00",
          "11:00-12:00",
          "13:00-14:00",
          "14:00-15:00",
          "15:00-16:00",
          "16:00-17:00"
        ],
        courses: [
          ["", "", "", "", "", "", "", ""],
          ["生物", "物理", "化学", "政治", "历史", "英语", "", "语文"],
          ["语文", "数学", "英语", "历史", "", "化学", "物理", "生物"],
          ["生物", "", "化学", "政治", "历史", "英语", "数学", "语文"],
          ["语文", "数学", "英语", "历史", "政治", "", "物理", "生物"],
          ["生物", "物理", "化学", "", "历史", "英语", "数学", "语文"],
          ["语文", "数学", "英语", "", "", "", "", ""]
        ]
      }
    };
  },
  created() {
    //获取学期选择列表
    this.gain_term_list();
    //获取周次选择列表
    this.gain_week_list();
  },
  methods: {
    //获取学期选择列表
    gain_term_list() {
      this.term_list = [
        { term_id: "1", term_name: "2020-2021第一学期" },
        { term_id: "2", term_name: "2020-2021第二学期" },
        { term_id: "3", term_name: "2019-2020第一学期" },
        { term_id: "4", term_name: "2019-2020第二学期" },
        { term_id: "5", term_name: "2018-2019第一学期" },
        { term_id: "6", term_name: "2018-2019第二学期" }
      ];
    },

    //获取周次选择列表
    gain_week_list() {
      this.week_list = [
        { week_id: "1", week_name: "第一周" },
        { week_id: "2", week_name: "第二周" },
        { week_id: "3", week_name: "第三周" },
        { week_id: "4", week_name: "第四周" },
        { week_id: "5", week_name: "第五周" },
        { week_id: "6", week_name: "第六周" },
        { week_id: "7", week_name: "第七周" },
        { week_id: "8", week_name: "第八周" },
        { week_id: "9", week_name: "第九周" },
        { week_id: "10", week_name: "第十周" }
      ];
    },

    //条件搜索
    search_lessonSchedule() {},

    /**
     * 数字转中文
     * @param {Number} num 需要转换的数字
     * @param {String} identifier 标识符
     * @returns {String} 转换后的中文
     */
    digital2Chinese(num, identifier) {
      const character = [
        "零",
        "一",
        "二",
        "三",
        "四",
        "五",
        "六",
        "七",
        "八",
        "九",
        "十",
        "十一",
        "十二"
      ];
      return identifier === "week" && (num === 0 || num === 7)
        ? "日"
        : character[num];
    }
  }
};
</script>

<style lang="scss" scoped>
.class-table {
  .table-wrapper {
    width: 100%;
    height: 100%;
    overflow: auto;
  }
  .tabel-container {
    margin: 7px;

    table {
      table-layout: fixed;
      width: 100%;

      thead {
        background-color: #67a1ff;
        th {
          color: #fff;
          line-height: 17px;
          font-weight: normal;
        }
      }
      tbody {
        background-color: #eaf2ff;
        td {
          color: #677998;
          line-height: 12px;
        }
      }
      th,
      td {
        width: 60px;
        padding: 12px 2px;
        font-size: 12px;
        text-align: center;
      }

      tr td:first-child {
        color: #333;
        .period {
          font-size: 8px;
        }
      }
    }
  }
}
</style>
